//
//  BaseTabbarViewController.m
//  quxiangtao
//
//  Created by xbmios on 2018/9/30.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "BaseTabbarViewController.h"
#import "CenterTabbar.h"
#import "BaseNavigationViewController.h"
#import "ForumViewController.h"
#import "JTNavigationController.h"
@interface BaseTabbarViewController ()<UITabBarControllerDelegate>

@property (assign, nonatomic) NSInteger selectItem;
//@property (strong, nonatomic) CenterTabbar *tabbar;
@property (strong, nonatomic) NSArray *VCArr;
@property (strong, nonatomic) NSArray *tabbarTtitle;
@property (strong, nonatomic) NSArray *normalArr;
@property (strong, nonatomic) NSArray *selectedArr;


@end

@implementation BaseTabbarViewController

+ (instancetype)sharedMainTabBarVC {
    
    static id instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        instance = [[self alloc] init];
        
    });
    
    return instance;
    
}
//HHBaseViewController  DLAiGouWebViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [UITabBar appearance].translucent = YES;
    
    NSArray *VCArr = @[@"NewHomeViewController", @"DLAiGouWebViewController", @"MineViewController"];
//    NSArray *VCArr = @[@"NewHomeViewController", @"DLAiGouWebViewController", @"WelfareViewController", @"MineViewController"];
    self.VCArr = VCArr;
    NSArray *tabbarTtitle = @[@"购物", @"自营", @"我的"];
//    NSArray *tabbarTtitle = @[@"购物", @"自营", @"福利", @"我的"];
    self.tabbarTtitle = tabbarTtitle;
    NSArray *normalArr = @[@"tab_gouwu_01", @"tab_ziying_04", @"tab_wode_02"];
//    NSArray *normalArr = @[@"tab_gouwu_01", @"tab_ziying_04", @"tab_fuli_05", @"tab_wode_02"];
    self.normalArr = normalArr;
    NSArray *selectedArr = @[@"tab_gouwu_02", @"tab_ziying_03", @"tab_wode"];
//    NSArray *selectedArr = @[@"tab_gouwu_02", @"tab_ziying_03",  @"tab_fuli_06", @"tab_wode"];
    self.selectedArr = selectedArr;
    
    [[UITabBar appearance] setBackgroundColor:Colorf7f7f7];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"666666"]} forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"FF748E"]} forState:UIControlStateSelected];

    // 初始化子控制器
    [self setUpAllChildViewController];

    self.delegate = self;
    self.selectedViewController = [self.viewControllers objectAtIndex:0];
    
}



- (BOOL)tabBarController:(UITabBarController*)tabBarController shouldSelectViewController:(UIViewController*)viewController {
    JTNavigationController *navCtrl = (JTNavigationController *)viewController;
    JTWrapViewController *rootCtrl = (JTWrapViewController*)navCtrl.topViewController;
    if ([rootCtrl.rootViewController isKindOfClass:[ForumViewController class]]) {
        return NO;
    }
    return YES;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    if (tabBarController.selectedIndex == self.selectItem) {
    }else{
//        [self.tabbar.centerBtn setImage:[[UIImage imageNamed:@"forumSelected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    }
}

- (void)setUpAllChildViewController {
    for (int i = 0; i < self.VCArr.count; i ++) {
        UIViewController *vc = [[NSClassFromString(self.VCArr[i]) alloc] init];
        vc.title = self.tabbarTtitle[i];
        JTNavigationController *nav = [[JTNavigationController alloc] initWithRootViewController:vc];
        nav.tabBarItem = [[UITabBarItem alloc] initWithTitle:self.tabbarTtitle[i] image:[[UIImage imageNamed:self.normalArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]  selectedImage:[[UIImage imageNamed:self.selectedArr[i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        [self addChildViewController:nav];
    }
}


@end
